{extend name='layout/base' /}
{block name='content'}
<section id="inner-headline">
    <div class="container">
        <div class="row">
            <div class="col-lg-12" style="text-align: center;">
                <h3 class="pageTitle"><a style="color:#D6DDE5;text-decoration: none;" href="{:url('index/Index/index')}">2019中国智慧小镇典型案例评选</a></h3>
            </div>
        </div>
    </div>
</section>
<section id="content">

    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="about-logo">
                    <h3>申报提示</h3>
                    <p>说明：本评选活动中的“智慧产业小镇”针对小镇产业的智慧化程度，“智慧小镇规划”针对小镇各方面的智慧化程度，以上两类均面向全部产业类型小镇；不同产业类型的小镇均可参评以上六类案例评选的任何一项，参评智慧小镇规划案例的小镇可同时申报其他五类案例评选。</p>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">

                <!-- Form itself -->
                <form id="form" action="{:url('index/Index/upload')}" method="post" enctype="multipart/form-data">
                    <h3>提交资料</h3>
                    <div class="form-group">
                        <label for="pname">项目名称:</label>
                        <div class="controls">
                            <input type="text" class="form-control" id="pname" name="pname" placeholder="项目名称">
                        </div>
                    </div>
                    <script type="text/javascript">
                        function select(value) {
                            console.log("ok");
                            if (value === "6") {
                                document.getElementById("other_type").style.display = "block";
                            }else{
                                document.getElementById("other_type").style.display = "none";
                                $('input[type=radio][name="type2"]:checked').prop("checked", false);
                            }
                        }
                    </script>
                    <div class="form-group">
                        <label for="type1">申报类型:</label>
                        <div class="controls">
                            <select class="form-control" name="type1" id="type1" onchange="select(this.value)">
                                <option value="">请选择申报类型</option>
                                <option value="1">2019全国十佳智慧小镇案例（综合类）</option>
                                <option value="2">2019全国十佳智慧产业小镇案例</option>
                                <option value="3">2019全国十佳智慧运营小镇案例</option>
                                <option value="4">2019全国十佳智慧管理小镇案例</option>
                                <option value="5">2019全国十佳智慧康体小镇案例</option>
                                <option value="6">2019全国十佳智慧小镇规划案例</option>
                            </select>
                        </div>
                    </div>
                    <div class="control-group" style="border:1px solid #ccc;padding: 10px;display: none;" id="other_type">
                        您还可以选择下面类型中的一项！
                        <div class="controls">
                            <label><input type="radio" name="type2" value="1"> 2019全国十佳智慧小镇案例（综合类）</label><br/>
                            <label><input type="radio" name="type2" value="2"> 2019全国十佳智慧产业小镇案例 </label><br/>
                            <label><input type="radio" name="type2" value="3"> 2019全国十佳智慧运营小镇案例 </label><br/>
                            <label><input type="radio" name="type2" value="4"> 2019全国十佳智慧管理小镇案例 </label><br/>
                            <label><input type="radio" name="type2" value="5"> 2019全国十佳智慧康体小镇案例 </label><br/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="unit">申报单位:</label>
                        <div class="controls">
                            <input type="text" class="form-control" id="unit" name="unit" placeholder="申报单位">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="contact">联系人:</label>
                        <div class="controls">
                            <input type="text" class="form-control" id="contact" name="contact" placeholder="联系人">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="phone">联系电话:</label>
                        <div class="controls">
                            <input type="text" class="form-control" id="phone" name="phone" placeholder="联系电话">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="email">电子邮箱:</label>
                        <div class="controls">
                            <input type="text" class="form-control" id="email" name="email" placeholder="电子邮箱">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="address">通信地址:</label>
                        <div class="controls">
                            <input type="text" class="form-control" id="address" name="address" placeholder="通信地址">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="file">上传资料:</label>
                        <div class="controls">
                            <input id="file" name="file" type="file" onchange="checkFileExt(this.value)"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="yzm">验证码:</label>
                        <div class="controls">
                            <input type="text" class="form-control" id="yzm" name="yzm" placeholder="验证码">
                        </div>
                        <div class="controls" style="text-align: center;">
                            <img src='/captcha.html' onclick="this.src='/captcha.html?t='+Math.random()" title="如错误请点击刷新验证码！"/>&nbsp;&nbsp;如错误请点击刷新！
                        </div>
                    </div>
                    <div id="loading"> </div> <!-- For success/fail messages -->
                    <style type="text/css">
                        #btn button,#btn a{
                            background: #002E5B;
                            color: #fff
                        }
                    </style>
                    <div class="row" style="text-align: center;" id="btn">
                        <a href="{:url('index/Index/index')}" class="btn btn-default">返回</a>
                        <button type="button" id="btnPost" class="btn btn-primary">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
{/block}
{block name='plugin'}
<link rel="stylesheet" href="__INDEX__/js/bootstrapvalidator/css/bootstrapValidator.min.css">
<script src="__INDEX__/js/bootstrapvalidator/js/bootstrapValidator.min.js"></script>
<link rel="stylesheet" href="__INDEX__/js/layer/skin/default/layer.css">
<script src="__INDEX__/js/layer/layer.js"></script>
<script type="text/javascript">
    //jQuery代码
    function checkFileExt(filename)
    {
        var flag = false; //状态
        var arr = ["zip","rar"];
        //取出上传文件的扩展名
        var index = filename.lastIndexOf(".");
        var ext = filename.substr(index+1);
        //alert(ext)
        //循环比较
        for(var i=0;i<arr.length;i++)
        {
            if(ext == arr[i])
            {
                flag = true; //一旦找到合适的，立即退出循环
                break;
            }
        }
        if(flag){
            return true;
        }else{
            layer.alert('您的文件格式不对，只支持zip,rar文件！');
            $("input#file").val("");
            return false;
        }
    }
    $(function () {
        $('form').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                pname: {
                    validators: {
                        notEmpty: {
                            message: '请填写项目名称！'
                        }
                    }
                },
                type1: {
                    validators: {
                        notEmpty: {
                            message: '请选择项目类型！'
                        }
                    }
                },
                unit: {
                    validators: {
                        notEmpty: {
                            message: '请填写申报单位！'
                        }
                    }
                },
                contact: {
                    validators: {
                        notEmpty: {
                            message: '请填写联系人！'
                        }
                    }
                },
                phone: {
                    validators: {
                        notEmpty: {
                            message: '请填写联系电话！'
                        }
                    }
                },
                email: {
                    validators: {
                        notEmpty: {
                            message: '请填写电子邮箱！'
                        },
                        emailAddress:{
                            message: '邮箱地址格式有误！'
                        }
                    }
                },
                address: {
                    validators: {
                        notEmpty: {
                            message: '请填写联系地址！'
                        }
                    }
                },
                file: {
                    validators: {
                        notEmpty: {
                            message: '请选择上传资料！'
                        }
                    }
                },
                yzm: {
                    validators: {
                        notEmpty: {
                            message: '请填写验证码！'
                        }
                    }
                },
            }
        });
        $('#btnPost').on('click',function(){
            $("#form").bootstrapValidator('validate');//提交验证
            if ($("#form").data('bootstrapValidator').isValid()) {
                //验证成功后的操作，如ajax
                //alert('ok');
                var form = new FormData(document.getElementById("form"));
                $.ajax({
                    url:"{:url('index/Index/upload')}",
                    type:"post",
                    data:form,
                    cache: false,
                    processData: false,
                    contentType: false,
                    beforeSend:function(XMLHttpRequest){
                        $("#loading").html("<img src='__INDEX__/img/loading.gif' />");
                        $("#btn").css("display", "none");
                    },
                    success:function(data){
                        var msg = '';
                        if (data.code === 1){
                            msg = data.msg + '，返回活动首页！';
                        }else{
                            msg = data.msg;
                        }
                        layer.confirm(msg, {
                            btn: ['确定'], //按钮
                            closeBtn:0,
                            icon:data.code
                        }, function(){
                            if(data.code === 1){
                                window.location.href="{:url('index/Index/index')}";
                            }
                            $("#loading").empty();
                            $("#btn").css("display", "block");
                            layer.closeAll('dialog');
                        }, function(){
                            if(data.code === 1){
                                window.location.href="{:url('index/Index/index')}";
                            }
                            $("#loading").empty();
                            $("#btn").css("display", "block");
                            layer.closeAll('dialog');
                        });

                    },
                    error:function(e){
                        alert("网络错误，请重试！！");
                    }
                });
            }

        });
    });
</script>
{/block}